﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using DevExpress.DevLocalizer;

namespace LanguageInfo.Forms
{
    public partial class MainForm : Form
    {
        public MainForm()
        {
            InitializeComponent();
            DevLocalizer();
            
        }

        private void ClearFontCol(string strName)
        {
            foreach (var itm in bar2.LinksPersistInfo)
            {
                var obj = (DevExpress.XtraBars.LinkPersistInfo)itm;
                if (obj.Item.Name == strName)
                {
                    //obj.Item.GlyphDisabled = imageList1.Images[0];
                    obj.Item.Enabled = false ;
                }
                else
                {
                    //obj.Item.GlyphDisabled = null;
                    obj.Item.Enabled = true;
                }

            }
        }
        #region 获取已打开的窗口
        /// <summary>
        /// 获取已打开的窗口
        /// </summary>
        /// <param name="typeForm"></param>
        /// <param name="tagKey"></param>
        /// <returns></returns>
        public Form GetShowSingleChildForm(Type typeForm, object tagKey)
        {
            foreach (Form f in MdiChildren)
            {
                if (f.GetType() == typeForm)
                {
                    if (tagKey != null && !tagKey.Equals(f.Tag))
                    {
                        continue;
                    }
                    return f;
                }
            }
            return null;

        }
        #endregion

        private void barCorporaInfo_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e)
        {
            try
            {
                Form _InputMainFrm = GetShowSingleChildForm(typeof(LanuageInfo.Forms.CorporaInfo.FrmMain), null);
                if (_InputMainFrm == null)
                {
                    _InputMainFrm = new LanuageInfo.Forms.CorporaInfo.FrmMain();
                    _InputMainFrm.MdiParent = this;
                    //_InputMainFrm.Dock = DockStyle.Fill;
                    //_InputMainFrm.MdiParent.Dock = DockStyle.Fill;
                    //_InputMainFrm.ControlBox = false;
                    //_InputMainFrm.MaximizeBox = false;
                    //_InputMainFrm.MaximizeBox = false;
                    _InputMainFrm.Show();
                    _InputMainFrm.WindowState = FormWindowState.Maximized;
                }
                else
                {
                    _InputMainFrm.Activate();

                }
                ClearFontCol("barCorporaInfo");
            }
            catch (Exception _ex)
            {
                //logging
            }
        }

        private void barWordsInfo_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e)
        {
            try
            {
                Form _InputMainFrm = GetShowSingleChildForm(typeof(LanuageInfo.Forms.WordsInfo.FrmMain), null);
                if (_InputMainFrm == null)
                {
                    _InputMainFrm = new LanuageInfo.Forms.WordsInfo.FrmMain();
                    _InputMainFrm.MdiParent = this;
                    _InputMainFrm.Show();
                    _InputMainFrm.WindowState = FormWindowState.Maximized;
                }
                else
                {
                    _InputMainFrm.Activate();
                }
                ClearFontCol("barWordsInfo");
            }
            catch (Exception _ex)
            {
                //logging
            }
        }

        private void barUserInfo_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e)
        {
            try
            {
                Form _InputMainFrm = GetShowSingleChildForm(typeof(LanuageInfo.Forms.UserInfo.FrmMain), null);
                if (_InputMainFrm == null)
                {
                    _InputMainFrm = new LanuageInfo.Forms.UserInfo.FrmMain();
                    _InputMainFrm.MdiParent = this;
                    _InputMainFrm.Show();
                    _InputMainFrm.WindowState = FormWindowState.Maximized;
                }
                else
                { 
                    _InputMainFrm.Activate();
                }
                ClearFontCol("barUserInfo");
            }
            catch (Exception _ex)
            {
                //logging
            }
        }
        #region  控件中文化
        /// <summary>
        /// 控件中文化
        /// </summary>
        private static void DevLocalizer()
        {
            DevEditLocalizer myeditLocalizer = new DevEditLocalizer();
            DevGridLocalizer mygridLocalizer = new DevGridLocalizer();
            DevBarLocalizer mybarLocalizer = new DevBarLocalizer();
            DevExpress.XtraEditors.Controls.Localizer.Active = myeditLocalizer;
            DevExpress.XtraGrid.Localization.GridLocalizer.Active = mygridLocalizer;
            DevExpress.XtraBars.Localization.BarResLocalizer.Active = mybarLocalizer;
        }
        #endregion
        private void barAboutUs_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e)
        {
            try
            {
                Form _InputMainFrm = GetShowSingleChildForm(typeof(LanuageInfo.Forms.AboutUs.FrmMain), null);
                if (_InputMainFrm == null)
                {
                    _InputMainFrm = new LanuageInfo.Forms.AboutUs.FrmMain();
                    _InputMainFrm.MdiParent = this;
                    _InputMainFrm.Show();
                    _InputMainFrm.WindowState = FormWindowState.Maximized;
                }
                else
                { 
                    _InputMainFrm.Activate();
                }
                ClearFontCol("barAboutUs");
            }
            catch (Exception _ex)
            {
                //logging
            }
        }
    }
    
}
